import axios from 'axios'
import store from "@/store";

import {Message } from 'element-ui';
import {wsSend} from "@/tools/sendMessage";

let instance = axios.create({
  baseURL: '',
  timeout: 10000,
  headers: {
    'Content-Type': 'application/json;charset=UTF-8'
  }
})
// eslint-disable-next-line no-unused-vars
let url=''
fetch('/static/ipConfig.json')
  .then((response) => response.json()) // 解析为 JSON
  .then((data) => {
    instance.defaults.baseURL = data.operateUrl// 访问 baseUrl
  })
  .catch((error) => {
    console.error('加载配置文件失败:', error);
  });


export const submitOperateRecord = (data,flag=true) => {

  if (flag!==false){
      Message.success({
        message: data.log_desc
      });
    }
    wsSend({"cmd":"WriteOperatorRecord","name":pointName,"message":data.log_desc})
    data.examId = store.state.user?.examId ?? undefined;
    data.studentId = store.state.user?.id??1
    data.questionId=store.state.user?.questionId??undefined
    data.paperId = store.state.user?.paperId??undefined
    return instance.post(`/kaoshi/qdapi/submitOperateLog
  `, data);
}

export const getOperateRecord = () => {

  const params = {
    studentId: store.state.user?.id??1,
    examId:store.state.user?.examId ?? undefined,
    questionId:store.state.user?.questionId??undefined
  };
  return instance.post(`/kaoshi/qdapi/getOperateRecord`, params);
}
export const saveGk=(data)=>{
  return instance.post('/kaoshi/qdapi/saveGk',data)
}
export const getGk=()=>{
  return instance.get('/kaoshi/qdapi/getGongKuangs')
}
export const changeGk=(data)=>{
  return instance.post('/kaoshi/qdapi/updateGongKuang',data)
}
export const delGk=(data)=>{
  return instance.post('/kaoshi/qdapi/delGongKuang',data)
}
export const saveJAn=(data)=>{
  return instance.post('/kaoshi/qdapi/saveTeach',data)
}
export const getJAn=()=>{
  return instance.get('/kaoshi/qdapi/getTeaches')
}
export const delJAn=(data)=>{
  return instance.post('/kaoshi/qdapi/delTeach',data)
}
export const addJaEvent=(data)=>{
  return instance.post('/kaoshi/qdapi/saveTeachContent',data)
}
export const delJaEvent=(data)=>{
  return instance.post('/kaoshi/qdapi/delTeachContent',data)
}

export const getTicketList = (data) => {
  return instance.post('/kaoshi/qdapi/getZyps',data)
}
export const saveTicket = (data) => {
  return instance.post('/kaoshi/qdapi/saveKpInfo', data)
}
export const updataTicket = (data) => {
  return instance.post('/kaoshi/qdapi/updateKpInfo', data)
}
export const getSy = () => {
  return instance.get('/kaoshi/qdapi/getKpSybs')
}
export const delZyp=(data)=>{
  return instance.post('/kaoshi/qdapi/deleKpInfo',data)
}
export const clearZyp=()=>{
  return instance.post('/kaoshi/qdapi/clearZyp',{id:store.state.user.id})
}
export const changeZypType=(data)=>{
  return instance.post('/kaoshi/qdapi/changeZypType',data)
}
export const deleteSy=(data)=>{
  return instance.post('/kaoshi/qdapi/deleKpSy',{id:data})
}
export const addSy=(data)=>{
  return instance.post('/kaoshi/qdapi/addKpSy',{name:data})
}
export const updateKpSy=(data)=>{
  return instance.post('/kaoshi/qdapi/updateKpSy',data)
}
